class Solution {
    public List<List<String>> groupAnagrams(String[] strs) {
        HashMap<String,List<String>>map=new HashMap<>();
         for(String s:strs)
         {
             char []result=s.toCharArray();
             Arrays.sort(result);
             String key =new String(result);
            List<String> list=map.getOrDefault(key,new ArrayList<String>());
            list.add(s);
            map.put(key,list);
         }
         return new ArrayList<List<String>>(map.values());
    }
}
